package algorithm;

import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

public class LuckyNumbers {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long x = scanner.nextLong();
        System.out.println(countLuckyNumbers(x));
        scanner.close();
    }

    public static long countLuckyNumbers(long x) {
        // 使用TreeSet来自动排序和去重
        TreeSet<Long> luckyNumbers = new TreeSet<>();

        // 初始种子
        luckyNumbers.add(1L);

        // 使用优先队列（最小堆）来按顺序生成数字
        PriorityQueue<Long> heap = new PriorityQueue<>();
        heap.offer(1L);

        while (!heap.isEmpty()) {
            long current = heap.poll();

            // 生成新的幸运数字：current * 3, current * 5, current * 7
            long[] multipliers = {3, 5, 7};
            for (long multiplier : multipliers) {
                long next = current * multiplier;
                // 如果不超过x且没有被处理过
                if (next <= x && !luckyNumbers.contains(next)) {
                    luckyNumbers.add(next);
                    heap.offer(next);
                }
            }
        }

        // 减去1，因为1不是幸运数字（题目从3开始）
        return luckyNumbers.size() - 1;
    }

}
